!(function(e, t) {
  "object" == typeof exports && "undefined" != typeof module
    ? t(exports, require("axios"))
    : "function" == typeof define && define.amd
    ? define(["exports", "axios"], t)
    : t(
        ((e = "undefined" != typeof globalThis ? globalThis : e || self).jingweiAxios = {}),
        e.axios
      );
})(this, function(e, t) {
  "use strict";
  function r(e) {
    return e && "object" == typeof e && "default" in e ? e : { default: e };
  }
  var o = r(t),
    n = function(e, t) {
      return (n =
        Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array &&
          function(e, t) {
            e.__proto__ = t;
          }) ||
        function(e, t) {
          for (var r in t) Object.prototype.hasOwnProperty.call(t, r) && (e[r] = t[r]);
        })(e, t);
    };
  function i(e, t) {
    if ("function" != typeof t && null !== t)
      throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
    function r() {
      this.constructor = e;
    }
    n(e, t), (e.prototype = null === t ? Object.create(t) : ((r.prototype = t.prototype), new r()));
  }
  var a,
    s = function() {
      (this.host = ""), (this.prefix = "/");
    },
    u = new Uint8Array(16);
  function p() {
    if (
      !a &&
      !(a =
        ("undefined" != typeof crypto &&
          crypto.getRandomValues &&
          crypto.getRandomValues.bind(crypto)) ||
        ("undefined" != typeof msCrypto &&
          "function" == typeof msCrypto.getRandomValues &&
          msCrypto.getRandomValues.bind(msCrypto)))
    )
      throw new Error(
        "crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported"
      );
    return a(u);
  }
  var c = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
  function f(e) {
    return "string" == typeof e && c.test(e);
  }
  for (var d = [], l = 0; l < 256; ++l) d.push((l + 256).toString(16).substr(1));
  function y(e, t, r) {
    var o = (e = e || {}).random || (e.rng || p)();
    if (((o[6] = (15 & o[6]) | 64), (o[8] = (63 & o[8]) | 128), t)) {
      r = r || 0;
      for (var n = 0; n < 16; ++n) t[r + n] = o[n];
      return t;
    }
    return (function(e) {
      var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0,
        r = (
          d[e[t + 0]] +
          d[e[t + 1]] +
          d[e[t + 2]] +
          d[e[t + 3]] +
          "-" +
          d[e[t + 4]] +
          d[e[t + 5]] +
          "-" +
          d[e[t + 6]] +
          d[e[t + 7]] +
          "-" +
          d[e[t + 8]] +
          d[e[t + 9]] +
          "-" +
          d[e[t + 10]] +
          d[e[t + 11]] +
          d[e[t + 12]] +
          d[e[t + 13]] +
          d[e[t + 14]] +
          d[e[t + 15]]
        ).toLowerCase();
      if (!f(r)) throw TypeError("Stringified UUID is invalid");
      return r;
    })(o);
  }
  var h = {
      host: /^(https?:)?(\/\/)?[a-zA-Z0-9.:]*\/?$/,
      path: /^(\/?[A-Za-z-_]+)*\/?$/,
      url: /^[A-Za-z0-9-_/{}?]*\??([A-Za-z0-9-_]+=[A-Za-z0-9-_/{}?]+&?)*$/
    },
    v = function(e, t, r) {
      var o = typeof e;
      if (o == t.type)
        switch (o) {
          case "object":
            Object.keys(e).forEach(function(r) {
              if (t.properties) {
                var o = t.properties.hasOwnProperty(r),
                  n = t.properties.hasOwnProperty("any");
                o
                  ? ((t.properties[r].checked = !0), v(e[r], t.properties[r], r))
                  : n
                  ? v(e[r], t.properties.any, r)
                  : console.error("unexpect field");
              }
            }),
              t.properties &&
                Object.keys(t.properties).forEach(function(e) {
                  var r = t.properties[e];
                  "any" != e &&
                    !1 !== r.required &&
                    !0 !== r.checked &&
                    console.error("field " + e + " lost");
                });
            break;
          case "string":
            t.validate && !h[t.validate].test(e) && console.error("validate " + r + " error");
        }
      else console.error("type error");
    },
    g = function(e) {
      return null !== e && "object" == typeof e;
    },
    m = function(e) {
      if (Array.isArray(e)) return e.map(m);
      if (g(e)) {
        var t = {};
        for (var r in e) t[r] = m(e[r]);
        return t;
      }
      return e;
    },
    q = ["get", "delete", "head", "options", "post", "put", "patch", "purge", "link", "unlink"],
    b = (function(e) {
      function t(t, r) {
        var o = e.call(this) || this;
        return (o.host = t.host || r.host), (o.prefix = t.prefix || r.prefix), o.init(t), o;
      }
      return (
        i(t, e),
        (t.prototype.init = function(e) {
          var t = q.find(function(t) {
              return e[t];
            }),
            r = e[t];
          (this.method = t),
            (this.url = (function() {
              for (var e = [], t = 0; t < arguments.length; t++) e[t] = arguments[t];
              return e
                .join("/")
                .replace(/[\/]+/g, "/")
                .replace(/\/\?/g, "?")
                .replace(/\/\#/g, "#")
                .replace(/\:\//g, "://");
            })(this.host, this.prefix, r));
        }),
        t
      );
    })(s),
    x = /{([a-zA-Z0-9-_]+)\??}/g,
    j = (function(e) {
      function t(t, r, o) {
        var n = e.call(this) || this;
        return (
          (n.queue = new Map()),
          (n.host = t.host || o.host),
          (n.prefix = t.prefix || o.prefix),
          (n.axiosInstance = o.axiosInstance),
          (n.config = t),
          (n.moduleName = r),
          (n.parent = o),
          n.validate(t),
          n.init(t),
          n
        );
      }
      return (
        i(t, e),
        (t.prototype.validate = function(e) {
          v(e, {
            type: "object",
            properties: {
              host: { type: "string", required: !1, validate: "host" },
              prefix: { type: "string", required: !1, validate: "path" },
              any: {
                type: "object",
                properties: {
                  get: { type: "string", required: !1, validate: "url" },
                  post: { type: "string", required: !1, validate: "url" },
                  put: { type: "string", required: !1, validate: "url" },
                  delete: { type: "string", required: !1, validate: "url" },
                  patch: { type: "string", required: !1, validate: "url" }
                }
              }
            }
          });
        }),
        (t.prototype.init = function(e) {
          var t = this;
          Object.keys(e).forEach(function(r) {
            var o = e[r];
            if (g(o)) {
              var n = new b(o, t);
              (n.apiName = r),
                (t[r] = function(e, o) {
                  var i = t.dataConfig(n, e),
                    a = i.reqUrl,
                    s = i.reqBody;
                  if (i.configError) return Promise.reject(" axios:配置错误，请F12查看消息");
                  var u = Object.assign({ apiName: r, moduleName: t.moduleName }, o, {
                    method: n.method,
                    url: a,
                    data: s
                  });
                  return t.setReqConfig(u), t.axiosInstance.request(u);
                }),
                (t[r] = new Proxy(t[r], {
                  get: function(e, o) {
                    var n;
                    return "loading" == o
                      ? (((n = t.queue.get(r)) && n.size) || 0) > 0
                      : "queue" == o
                      ? (n = t.queue.get(r)) || new Set()
                      : e[o];
                  }
                }));
            }
          });
        }),
        (t.prototype.dataConfig = function(e, t) {
          void 0 === t && (t = {});
          var r = !(!t.$query && !t.$body),
            o = {},
            n = {},
            i = !1;
          r ? ((o = t.$query), (n = t.$body)) : ((o = m(t) || {}), (n = m(t) || {}));
          var a = e.url.replace(x, function(e, t, a, s, u) {
            var p = o[t];
            return (
              r || delete n[t],
              delete o[t],
              p ||
                (e.endsWith("?}")
                  ? ""
                  : ((i = !0),
                    void console.error("error " + e + "参数 缺少值或可设为可空参数;", { url: s })))
            );
          });
          return { configError: i, reqUrl: a, reqBody: n };
        }),
        (t.prototype.onRequest = function(e) {
          var t = this.queue.get("" + e.apiName);
          t || this.queue.set("" + e.apiName, (t = new Set())), t.add(e);
        }),
        (t.prototype.onRequestResolve = function(e) {
          this.queue.get("" + e.apiName).delete(e);
        }),
        (t.prototype.onRequestReject = function(e) {
          this.queue.get("" + e.apiName).delete(e);
        }),
        (t.prototype.setReqConfig = function(e) {
          var t = this.parent.config;
          t.traceId &&
            (e.headers = Object.assign({}, e.headers, { traceId: t.traceId + "-" + y() }));
        }),
        t
      );
    })(s),
    w = { traceId: "ai_axios" },
    _ = (function(e) {
      function t(t, r) {
        var n = e.call(this) || this;
        return (
          (n.host = t.host),
          (n.prefix = t.prefix),
          (n.config = Object.assign({}, w, r)),
          (n.axiosInstance = o.default.create(n.config)),
          n.validate(t),
          n.init(t),
          n
        );
      }
      return (
        i(t, e),
        (t.prototype.validate = function(e) {
          v(e, {
            type: "object",
            properties: {
              host: { type: "string", required: !1, validate: "host" },
              prefix: { type: "string", required: !1, validate: "path" },
              any: { type: "object" }
            }
          });
        }),
        (t.prototype.init = function(e) {
          var t = this;
          Object.keys(e).forEach(function(r) {
            var o = e[r];
            if (g(o)) {
              var n = new j(o, r, t);
              t[r] = n;
            }
          });
        }),
        t
      );
    })(s);
  (e.create = _), Object.defineProperty(e, "__esModule", { value: !0 });
});
